package com.ll.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ll.blog.common.ApiResponse;
import com.ll.blog.contant.ArticleStatusEnum;
import com.ll.blog.entity.Article;
import com.ll.blog.service.IArticleService;
import com.ll.blog.service.ICategoriesService;
import com.ll.blog.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 普通接口
 */
@RestController
public class publicController {
    @Autowired
    ITagService tagService;
    @Autowired
    ICategoriesService categoriesService;
    @Autowired
    IArticleService articleService;

    /**
     * 获取文章，分类，标签总数
     * @return
     */
    @GetMapping("/info")
    public ApiResponse getBlogDetail(){
        long count = tagService.count();
        long count1 = categoriesService.count();
        long count2 = articleService.count(new LambdaQueryWrapper<Article>().eq(Article::getStatus, ArticleStatusEnum.RELEASED));
        HashMap<Object, Object> map = new HashMap<>();
        map.put("article_num",count2);
        map.put("class_num",count1);
        map.put("tag_num",count);
        return ApiResponse.success(map);
    }
}
